package com.shaco.heroproject.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.shaco.heroproject.R;
import com.shaco.heroproject.demo.MyItemOnClickListener;
import com.shaco.heroproject.entity.ResultStrategy;

import java.util.List;

/**
 * Created by dllo on 15/11/4.
 */
public class HeroInforStrategyAdapter extends RecyclerView.Adapter<HeroInforStrategyAdapter.HeroInforStrategyHolder> {
//    private RequestQueue queue;
//private VolleySingleton queue;
    private List<ResultStrategy> result;
    private MyItemOnClickListener myItemOnClickListener;

    public HeroInforStrategyAdapter(Context c) {

//        queue = Volley.newRequestQueue(c);
    }

    //item的点击事件
    public void setOnItemClickListener(MyItemOnClickListener listener) {
        this.myItemOnClickListener=listener;
    }


    @Override
    public HeroInforStrategyHolder onCreateViewHolder(ViewGroup viewGroup, int position) {
        LayoutInflater inflater = LayoutInflater.from(viewGroup.getContext());
        View v = inflater.inflate(R.layout.hero_infor_strateg_item, null);
        return new HeroInforStrategyHolder(v,myItemOnClickListener);
    }

    @Override
    public void onBindViewHolder(HeroInforStrategyHolder holder, int position) {
        if (result != null && result.size() > 0) {
            ResultStrategy results = result.get(position);
            holder.heroInforStrategy_titleTv.setText(results.getTitle());

        }

    }

    @Override
    public int getItemCount() {
        return result != null && result.size() > 0 ? result.size() : 0;
    }

    // 增加数据
    public void addData(List<ResultStrategy> results) {
        result = results;
        notifyDataSetChanged();
    }

    class HeroInforStrategyHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        private TextView heroInforStrategy_titleTv;
        private MyItemOnClickListener mListener;

        public HeroInforStrategyHolder(View v,MyItemOnClickListener listener) {
            super(v);
            // TODO Auto-generated constructor stub
            heroInforStrategy_titleTv = (TextView) v.findViewById(R.id.heroInforStrategy_titleTv);

            //--------------------//
            this.mListener=listener;
            v.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
            if (mListener!=null){
                mListener.onItemClick(v,getPosition());
            }
        }
    }
}
